load("~/Documents/Nonparametric Statisics/Project/clean data/full_collisions.RData")
glimpse(full_collisions)
## Rows: 2,585,717
## Columns: 37
## $ accident_index                              <chr> "200501BS00001", "200501BS…
## $ accident_year                               <dbl> 2005, 2005, 2005, 2005, 20…
## $ accident_reference                          <chr> "01BS00001", "01BS00002", …
## $ location_easting_osgr                       <dbl> 525680, 524170, 524520, 52…
## $ location_northing_osgr                      <dbl> 178240, 181650, 182240, 17…
## $ longitude                                   <dbl> -0.191170, -0.211708, -0.2…
## $ latitude                                    <dbl> 51.48910, 51.52007, 51.525…
## $ police_force                                <fct> Metropolitan Police, Metro…
## $ accident_severity                           <fct> Serious, Slight, Slight, S…
## $ number_of_vehicles                          <dbl> 1, 1, 2, 1, 1, 2, 2, 1, 2,…
## $ number_of_casualties                        <dbl> 1, 1, 1, 1, 1, 1, 1, 2, 2,…
## $ date                                        <date> 2005-01-04, 2005-01-05, 2…
## $ day_of_week                                 <fct> Tuesday, Wednesday, Thursd…
## $ time                                        <time> 17:42:00, 17:36:00, 00:15…
## $ local_authority_district                    <fct> "Kensington and Chelsea", …
## $ local_authority_ons_district                <chr> "E09000020", "E09000020", …
## $ local_authority_highway                     <chr> "E09000020", "E09000020", …
## $ first_road_class                            <fct> A, B, C, A, Unclassified, …
## $ first_road_number                           <dbl> 3218, 450, 0, 3220, 0, 0, …
## $ road_type                                   <fct> Single carriageway, Dual c…
## $ speed_limit                                 <dbl> 30, 30, 30, 30, 30, 30, 30…
## $ junction_detail                             <fct> Not at junction or within …
## $ junction_control                            <fct> Data missing or out of ran…
## $ second_road_class                           <fct> Not at junction or within …
## $ second_road_number                          <dbl> -1, 0, -1, -1, -1, -1, 0, …
## $ pedestrian_crossing_human_control           <fct> None within 50 metres, Non…
## $ pedestrian_crossing_physical_facilities     <fct> "Zebra", "Pedestrian phase…
## $ light_conditions                            <fct> Daylight, Darkness - light…
## $ weather_conditions                          <fct> Raining no high winds, Fin…
## $ road_surface_conditions                     <fct> Wet or damp, Dry, Dry, Dry…
## $ special_conditions_at_site                  <fct> None, None, None, None, No…
## $ carriageway_hazards                         <fct> None, None, None, None, No…
## $ urban_or_rural_area                         <fct> Urban, Urban, Urban, Urban…
## $ did_police_officer_attend_scene_of_accident <fct> Yes, Yes, Yes, Yes, Yes, Y…
## $ trunk_road_flag                             <fct> Non-trunk, Non-trunk, Non-…
## $ lsoa_of_accident_location                   <chr> "E01002849", "E01002909", …
## $ datetime                                    <dttm> 2005-01-04 17:42:00, 2005…

expoting the spatial features of the data

df_22 <- full_collisions %>% filter(accident_year == 2022)

df_sf <- format_sf(df_22)
## 22 rows removed with no coordinates

the police forces:

plot(df_sf[,6])

districts:

plot(df_sf[,14:15])

road types:

plot(df_sf[,16])

road tyope and speed limits:

plot(df_sf[,18:19])

urban rural

plot(df_sf[,31])

geometry, this are all points:

plot(df_sf[,36])

by police bounddaries:

df_sf %>% 
  select(n_fatalities = accident_index) %>% 
  aggregate(by = police_boundaries, FUN = length) %>% 
  plot()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()

plotting the london crashes

london <- df_sf %>% filter(police_force == "Metropolitan Police")

accident severity:

plot(london[,7])

road class:

plot(london[,16])